/***********************************************************************
 *
 * MODULE NAME:    avrcp_core.h
 * PROJECT CODE:   host side stack
 * DESCRIPTION:    Audio/video distribution transport profile
 * MAINTAINER:     Mark Donnelly
 *
 *
 * LICENSE:
 *     This source code is copyright (c) 2008 RDA Ltd.
 *     All rights reserved.
 *
 * REVISION HISTORY:
 * 
 *
 * ISSUES:
 * 
 ***********************************************************************/
#ifndef AVRCP_CORE
#define AVRCP_CORE
 #include "avrcp.h"

/* L2CAP PSM */

#define AVCTP0_TRANSACTION_SHIFT	4
#define AVCTP0_PACKET_TYPE_MASK		0x0c
#define AVCTP0_PACKET_TYPE_SINGLE	0x00
#define AVCTP0_PACKET_TYPE_START	0x04
#define AVCTP0_PACKET_TYPE_CONTINUE	0x08
#define AVCTP0_PACKET_TYPE_END		0x0C
#define AVCTP0_CR_MASK				0x02
#define AVCTP0_CR_COMMAND			0x00
#define AVCTP0_CR_RESPONSE			0x02
#define AVCTP0_IPID					0x01
#define AVCTP1_PROFILE_AVRCP_HIGH	0x11
#define AVCTP2_PROFILE_AVRCP_LOW	0x0e

#define AVRCP0_CTYPE_CONTROL			0x00
#define AVRCP0_CTYPE_STATUS				0x01
#define AVRCP1_SUBUNIT_TYPE_MASK		0xf8
#define AVRCP1_SUBUNIT_TYPE_SHIFT		3
#define AVRCP1_SUBUNIT_ID_MASK			0x07
#define AVRCP1_UNIT						0xff

#define AVRCP2_PASSTHROUGH				0x7C
#define AVRCP2_UNITINFO					0x30
#define AVRCP2_SUBUNITINFO				0x31
#define AVRCP2_VENDORDEPENDENT			0x00
#define AVRCP3_PASSTHROUGH_OP_MASK		0x7f
#define AVRCP3_PASSTHROUGH_STATE_MASK	0x80
#define AVRCP3_SUBUNITINFO_PAGE_SHIFT	4
#define AVRCP3_SUBUNITINFO_EXTEND_MASK	7
#define AVRCP4_UNITINFO_UNIT_TYPE_SHIFT	3
#define AVRCP4_UNITINFO_UNIT_MASK		7

#define AVRCP_TOTAL_HEADER_SIZE			6



/*!
	@brief The page data length.
*/
#define PAGE_DATA_LENGTH	(4)

typedef enum
{
    AVRCP_MESSAGE_VALID,
    AVRCP_MESSAGE_INVALID
}t_AVRCP_MESSAGE_VALID;

typedef enum
{
    AVRCP_TYPE_COMMAND,
    AVRCP_TYPE_RESPONSE
}t_AVRCP_MESSAGE_TYPE;

/*! 
	@brief AVRCP responses 
*/
typedef enum
{
	/*! The request is not implemented */
	AVCTP_RESPONSE_NOT_IMPLEMENTED=0X08,
	/*! The request has been accepted */
	AVCTP_RESPONSE_ACCEPTED = 0x09,			
	/*! The request has been rejected */
	AVCTP_RESPONSE_REJECTED = 0x0a,			
	/*! The target is in a state of transition */
	AVCTP_RESPONSE_IN_TRANSTION = 0x0b,	
	/*! A stable response */
	AVCTP_RESPONSE_STABLE = 0x0c,			
	/*! The target devices state has changed */
	AVCTP_RESPONSE_CHANGED = 0x0d,			
	/*! The response is an interim response */
	AVCTP_RESPONSE_INTERIM = 0x0f,			
	/*! The specified profile is not acceptable */
	AVCTP_RESPONSE_BAD_PROFILE				
} t_AVRCP_RESPONSE_TYPE;


/*!
	@brief AVRCP status codes 
*/
typedef enum
{
	/*! Operation was successful. */
	AVRCP_SUCCESS = (0),			
	/*! Operation failed. */
	AVRCP_FAI,						
	/*! Not enough resources. */
	AVRCP_NO_RESOURCE,				
	/*! Request is not supported in the current state. */
	AVRCP_BAD_STATE,				
	/*! Operation timed out before completion. */
	AVRCP_TIIMEOUT,					
	/*! Device specified is not connected. */
	AVRCP_DEVICE_NOT_CONNECTED,		
	/*! Operation is already in progress. */
	AVRCP_BUSY,						
	/*! Requested operation is not supported. */
	AVRCP_UNSUPPORTED,				
	/*! Sink supplied was invalid. */
	AVRCP_INVALID_SINK,
	/*! Link loss occurred. */
	AVRCP_LINK_LOSS
} t_AVRCP_STATUS_CODE;


/*!
	@brief Subunit types 
*/
typedef enum
{
	SUBUNIT_MONITOR			= (0x0),
	SUBUNIT_AUDIO,
	SUBUNIT_PRINTER,
	SUBUNIT_DISC,
	SUBUNIT_TAPE_RECORDER_PLAYER,
	SUBUNIT_TUNER,
	SUBUNIT_CA,
	SUBUNIT_CAMERA,
	SUBUNIT_RESERVED,
	SUBUNIT_PANEL,
	SUBUNIT_BULLETIN_BOARD,
	SUBUNIT_CAMERA_STORAGE,
	/* 0x0c - 0x1b Reserved */
	SUBUNIT_VENDOR_UNIQUE	= (0x1c),
	SUBUNIT_RESERVED_FOR_ALL,
	SUBUNIT_EXTENDED,
	SUBUNIT_UNIT
} t_AVC_SUBUNIT_TYPE;

/*!
	@brief AVRCP device type
       The avrcp library can be configured to be either a target or a controller  device.
*/
typedef enum
{
	AVRCP_NONE,
	AVRCP_PASSTHROUGH,
	AVRCP_UNIT_INFO,
	AVRCP_SUBUNIT_INFO,
	AVRCP_VENDOR
} t_AVRCP_PENDING;


typedef enum
{
	AVRCP_FRAG_NONE,
	AVRCP_FRAG_START,
	AVRCP_FRAG_CONTINUE,
	AVRCP_FRAG_END
} t_AVRCP_FRAGMENT;

typedef struct __AVRCP
{
	//TaskData            task;
	t_AVRCP_STATE	      state;
	t_AVRCP_PENDING	      pending;
	t_AVC_OPERATION_ID	  pending_key;
	t_AVRCP_DEVICE_TYPE   device_type;
	u_int8               block_received_data;
	u_int8			     watchdog;
	t_channelId		     cid;
	//Sink 			     sink;
	u_int8			     transaction_label;
	t_AVRCP_FRAGMENT   fragmented;
	u_int16 			     l2cap_mtu;
	u_int16			      priority;
	
    t_bdaddr 			device_addr;
	u_int8			        *identifier;
} AVRCP;


t_AVRCP_STATE Get_Avrcp_State(void);
void Avrcp_Handle_Received_Data(u_int8* ptr,t_channelId cid, u_int16 packet_size);
void Avrcp_Set_Notification(void);

#endif /* AVRCP_CORE*/

